package com.linuxgt.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuteng
 * @date 17-11-17
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket demoApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .host("localhost:52480")
                .select()
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        VendorExtension vendorExtension = new StringVendorExtension("test", "test");
        List<VendorExtension> list = new ArrayList<>();
        list.add(vendorExtension);
        return new ApiInfo("restful api demo",
                "swagger restful api demo",
                "v2",
                "localhost",
                new Contact("liuteng", "", "test@126.com"),
                "GPL",
                "http://demo.cn",
                list);
    }
}
